home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / Excel / Sheet.jar / sheet / Operand.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-09-03  |  2.0 KB  |  102 lines

  1. package sheet;
  2.  
  3. class Operand {
  4.    private static final byte EMPTY = 0;
  5.    private static final byte TEXT = 1;
  6.    private static final byte NUMBER = 2;
  7.    private static final byte NAME = 3;
  8.    private byte type;
  9.    private String text;
  10.    private int number;
  11.  
  12.    Operand(int var1) {
  13.       this.number = var1;
  14.       this.type = 2;
  15.       this.text = String.valueOf(var1);
  16.    }
  17.  
  18.    Operand(String var1) {
  19.       int var2 = var1.length();
  20.       if (var2 == 0) {
  21.          this.text = "";
  22.          this.type = 0;
  23.       } else if (var1.charAt(0) == '"' && var1.charAt(var2 - 1) == '"') {
  24.          this.text = var1.substring(1, var2 - 1);
  25.          this.type = 1;
  26.       } else {
  27.          this.text = var1;
  28.  
  29.          try {
  30.             this.number = Integer.parseInt(this.text);
  31.             this.type = 2;
  32.          } catch (NumberFormatException var4) {
  33.             this.type = 3;
  34.          }
  35.       }
  36.  
  37.    }
  38.  
  39.    Operand(String var1, boolean var2) {
  40.       if (var1.length() == 0) {
  41.          this.text = var1;
  42.          this.type = 0;
  43.       } else {
  44.          this.text = var1;
  45.          if (var2) {
  46.             try {
  47.                this.number = Integer.parseInt(this.text);
  48.                this.type = 2;
  49.             } catch (NumberFormatException var4) {
  50.                this.type = 1;
  51.             }
  52.          } else {
  53.             this.type = 1;
  54.          }
  55.       }
  56.  
  57.    }
  58.  
  59.    static final boolean isNumber(Operand var0) {
  60.       return var0 == null || var0.type == 0 || var0.type == 2;
  61.    }
  62.  
  63.    static final boolean isName(Operand var0) {
  64.       return var0 != null && var0.type == 3;
  65.    }
  66.  
  67.    static final int getNumber(Operand var0) throws NumberFormatException {
  68.       if (var0 == null) {
  69.          return 0;
  70.       } else {
  71.          switch (var0.type) {
  72.             case 0:
  73.                return 0;
  74.             case 2:
  75.                return var0.number;
  76.             default:
  77.                throw new NumberFormatException("Not a number: '" + var0.text + "'");
  78.          }
  79.       }
  80.    }
  81.  
  82.    static final String getText(Operand var0) throws NumberFormatException {
  83.       if (var0 == null) {
  84.          return "";
  85.       } else if (var0.type != 3) {
  86.          return var0.text;
  87.       } else {
  88.          throw new NumberFormatException("Not a text: '" + var0.text + "'");
  89.       }
  90.    }
  91.  
  92.    static final String getName(Operand var0) throws NumberFormatException {
  93.       if (var0 == null) {
  94.          throw new NumberFormatException("No data");
  95.       } else if (var0.type == 3) {
  96.          return var0.text;
  97.       } else {
  98.          throw new NumberFormatException("Not a name: '" + var0.text + "'");
  99.       }
  100.    }
  101. }
  102.